﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CuitWinComboBox.cs" company="">
//   
// </copyright>
// <summary>
//   The cuit win combo box.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace UITest.CUIT.CuitControls.WinControls
{
    using System.Linq;

    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

    /// <summary>
    ///     The cuit win combo box.
    /// </summary>
    public class CuitWinComboBox : CuitWinControl<WinComboBox>
    {
        #region Constructors and Destructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="CuitWinComboBox" /> class.
        /// </summary>
        public CuitWinComboBox()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinComboBox"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        public CuitWinComboBox(UITestControl testControl)
            : base(testControl)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinComboBox"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinComboBox(UITestControl testControl, string searchProperties)
            : base(testControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinComboBox"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinComboBox(UITestControl testControl, string searchProperties, string filterProperties)
            : base(testControl, searchProperties, filterProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinComboBox"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinComboBox(ICuitControlBase wrappedControl, string searchProperties)
            : base(wrappedControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinComboBox"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinComboBox(ICuitControlBase wrappedControl, string searchProperties, string filterProperties)
            : base(wrappedControl, searchProperties, filterProperties)
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets or sets the editable item.
        /// </summary>
        public string EditableItem
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.EditableItem;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value);
                this._control.EditableItem = value;
            }
        }

        /// <summary>
        ///     Gets or sets a value indicating whether expanded.
        /// </summary>
        public bool Expanded
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Expanded;
            }

            set
            {
                this._control.WaitForControlReady();
                this.WriteTestOutput(value.ToString());
                this._control.Expanded = value;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether is editable.
        /// </summary>
        public bool IsEditable
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.IsEditable;
            }
        }

        /// <summary>
        ///     Gets the count of the items in the combo box.
        /// </summary>
        public int ItemCount
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Items.Count;
            }
        }

        /// <summary>
        ///     Gets the items in a string array of the html combo box.
        /// </summary>
        public string[] Items
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Items.Cast<string>().ToArray();
            }
        }

        /// <summary>
        ///     Gets the selected index in a combo box.
        /// </summary>
        public int SelectedIndex
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.SelectedIndex;
            }
        }

        /// <summary>
        ///     Gets the selected item in a combo box.
        /// </summary>
        public string SelectedItem
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.SelectedItem;
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The item exists.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool ItemExists(string text)
        {
            this._control.WaitForControlReady();
            return this.Items.Contains(text);
        }

        /// <summary>
        /// The select item.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        public void SelectItem(string item)
        {
            this._control.WaitForControlReady();
            this._control.SelectedItem = item;
            this.WriteTestOutput(string.Empty);
        }

        /// <summary>
        /// The select item.
        /// </summary>
        /// <param name="index">
        /// The index.
        /// </param>
        public void SelectItem(int index)
        {
            this._control.WaitForControlReady();
            this._control.SelectedIndex = index;
            this.WriteTestOutput(string.Empty);
        }

        #endregion
    }
}